package controller

import (
	"SystemExploration/mongodb"
	"github.com/gin-gonic/gin"
)

type Logs struct{}

// 路由
func (that *Logs) Router(engine *gin.RouterGroup) {
	engine.POST("/log/list", that.logs)
}

func (that *Logs) logs(c *gin.Context) {
	listRespone := LogListRequest{}
	if err := c.ShouldBind(&listRespone); err != nil {
		c.JSON(200, gin.H{
			"code": "402",
			"msg":  "参数错误",
		})
		return
	}
	list, count, _ := mongodb.FindLogAll(listRespone.Page, listRespone.Limit, listRespone.Serach)
	var resplist = []LogListData{}
	for _, v := range list {
		var elem LogListData
		elem.TaskName = v.TaskName
		elem.AddTime = v.AddTime
		elem.Consuming = v.Consuming
		elem.Result = v.Result
		resplist = append(resplist, elem)
	}

	response := &LogListRespon{
		Code:  200,
		Msg:   "成功",
		Count: count,
		Data:  resplist,
	}

	c.JSON(200, response)
	return
}
